/*
 * Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
 */
package proxy.Static;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Description:
 *
 * @author wzz
 * @since: 1.0
 * Create Date Time: 2018/12/14 9:52
 * Update Date Time:
 */
public class JdkProxyHandler {

    //用来接收真实对象
    private Object realStar;
    public JdkProxyHandler(Star star){
        this.realStar = star;
    }

    //给真实对象生成一个代理对象实例
    public Object getProxyObject() {
        return Proxy.newProxyInstance(realStar.getClass().getClassLoader(),
                realStar.getClass().getInterfaces(), (proxy, method, args) -> {

                    System.out.println("代理先进行谈判……");
                    // 唱歌需要明星自己来唱
                    Object object = method.invoke(realStar, args);
                    System.out.println("演出完代理去收钱……");
                    return object;
                });
    }
}
